package com.example.zyfypt_206shj.fragement;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zyfypt_206shj.R;
import com.example.zyfypt_206shj.adapter.TcaseAdapter;
import com.example.zyfypt_206shj.adapter.TwareAdapter;
import com.example.zyfypt_206shj.bean.SessionID;
import com.example.zyfypt_206shj.bean.TcaseBean;
import com.example.zyfypt_206shj.bean.TwareBean;
import com.example.zyfypt_206shj.bean.UserInfo;
import com.example.zyfypt_206shj.iface.TcaseListener;
import com.example.zyfypt_206shj.iface.TwareListener;
import com.example.zyfypt_206shj.model.TcaseModel;
import com.example.zyfypt_206shj.model.TwareModel;

import java.util.List;


/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment3 extends Fragment {
    private View view=null;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private TwareAdapter twareAdapter;
    private List<TwareBean> list=null;
    private TwareListener twareListener = new TwareListener() {
        @Override
        public void onResponse(List<TwareBean> beanlist) {
            list = beanlist;
            twareAdapter.setList(list);
            twareAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(context, "fail" + msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment3,container,false);
        //获取布局上的控件，注意通过view获取
        //返回动态生成的view
        initRecyclerView();
        TwareModel twareModel = new TwareModel();
        twareModel.getResultList("tware", 1, SessionID.sessionID, twareListener);
        return view;
    }
    private void initRecyclerView(){
        layoutManager = new LinearLayoutManager(getContext());

        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerView3);
        //创建默认线性布局
        recyclerView.setLayoutManager(layoutManager);
        //固定每个item的高度，可以提高性能
        recyclerView.setHasFixedSize(true);
        //获取数据
        //list=getData();
        //实例化adapter
        twareAdapter=new TwareAdapter(getContext());
        twareAdapter.setList(list);
        recyclerView.setAdapter(twareAdapter);
    }
}
